package com.huishu.goods.controller;


import com.alibaba.fastjson.JSON;
import com.huishu.commons.pojo.Result;
import com.huishu.commons.pojo.vo.FullReductionVO;
import com.huishu.goods.pojo.dto.ProductFullReductionCreateDTO;
import com.huishu.goods.pojo.dto.ProductFullReductionPageDTO;
import com.huishu.goods.pojo.dto.ProductFullReductionUpdateDTO;
import com.huishu.goods.service.ProductFullReductionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author generator@ljj
 * @since 2023-04-10
 */
@RestController
@RequestMapping("/product-full-reduction")
@Slf4j
public class ProductFullReductionController {

    @Autowired
    private ProductFullReductionService productFullReductionService;


    @PostMapping("/find")
    public Result<List<FullReductionVO>> find(@RequestBody List<Long> ids) {
        return productFullReductionService.find(ids);
    }

    @PostMapping("/create")
    public Result create(@RequestBody ProductFullReductionCreateDTO productFullReductionCreateDTO) {
        log.info("新增满减活动:{}", JSON.toJSONString(productFullReductionCreateDTO));
        return productFullReductionService.create(productFullReductionCreateDTO);
    }

    @PostMapping("/update")
    public Result modify(@RequestBody ProductFullReductionUpdateDTO productFullReductionUpdateDTO) {
        log.info("修改满减活动:{}", JSON.toJSONString(productFullReductionUpdateDTO));
        return productFullReductionService.modify(productFullReductionUpdateDTO);
    }

    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Long id) {
        return productFullReductionService.findById(id);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        return productFullReductionService.delete(id);
    }

    @PostMapping("/pageList")
    public Result pageList(@RequestBody ProductFullReductionPageDTO productFullReductionPageDTO) {
        log.info("分页查询满减活动:{}", JSON.toJSONString(productFullReductionPageDTO));
        return productFullReductionService.pageList(productFullReductionPageDTO);
    }
}
